package com.example.frn.service.impl;

import com.example.frn.dao.CategoryMapper;
import com.example.frn.entity.Category;
import com.example.frn.entity.Film;
import com.example.frn.service.CategoryService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryMapper mapper;

    @Override
    public boolean save(Category category) {
        return mapper.insert(category)>0;
    }

    @Override
    public boolean removeById(Integer id) {
        return mapper.deleteById(id)>0;
    }


    @Override
    public boolean updateById(Category category) {
        return mapper.updateById(category) >0;
    }


    @Override
    public Category getById(Integer id) {
        return mapper.selectById(id);
    }


    @Override
    public List<Category> list() {
        return mapper.List();
    }


    @Override
    public PageInfo<Category> page(int pageNumber, int pageSize) {
        //Page<Category> page = new Page<>(pageNumber,pageSize);
        //先分页
        PageHelper.startPage(pageNumber,pageSize);
        List<Category> list = mapper.List();
        return new PageInfo<>(list);
    }

    @Override
    public List<Film> listForFilm(Integer id) {
        return mapper.listForFilm(id);
    }
}
